package com.ruoyi.web.controller.fenxi;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.enums.OrgRistTypeEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ROrgRiskLevel;
import com.ruoyi.system.service.IROrgRiskLevelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 风险等级统计标Controller
 * 
 * @author ruoyi
 * @date 2022-09-25
 */
@Controller
@RequestMapping("/system/level")
public class ROrgRiskLevelController extends BaseController
{
    private String prefix = "system/level";

    @Autowired
    private IROrgRiskLevelService rOrgRiskLevelService;

//    @RequiresPermissions("system:level:view")
    @GetMapping()
    public String level()
    {
        return prefix + "/level";
    }

    /**
     * 查询风险等级统计标列表
     */
//    @RequiresPermissions("system:level:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ROrgRiskLevel rOrgRiskLevel)
    {
        startPage();
        List<ROrgRiskLevel> list = rOrgRiskLevelService.selectROrgRiskLevelList(rOrgRiskLevel);
        return getDataTable(list);
    }

    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo glist(ROrgRiskLevel rOrgRiskLevel)
    {
        startPage();
        List<ROrgRiskLevel> list = rOrgRiskLevelService.selectROrgRiskLevelList(rOrgRiskLevel);
        for (ROrgRiskLevel orgRiskLevel : list) {
            orgRiskLevel.setLev(Integer.parseInt(orgRiskLevel.getName()));
            orgRiskLevel.setName(OrgRistTypeEnum.getOrgRistTypeEnumByCode(orgRiskLevel.getName()));
        }
        return getDataTable(list);
    }

    /**
     * 导出风险等级统计标列表
     */
//    @RequiresPermissions("system:level:export")
    @Log(title = "风险等级统计标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ROrgRiskLevel rOrgRiskLevel)
    {
        List<ROrgRiskLevel> list = rOrgRiskLevelService.selectROrgRiskLevelList(rOrgRiskLevel);
        ExcelUtil<ROrgRiskLevel> util = new ExcelUtil<ROrgRiskLevel>(ROrgRiskLevel.class);
        return util.exportExcel(list, "风险等级统计标数据");
    }

    /**
     * 新增风险等级统计标
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险等级统计标
     */
//    @RequiresPermissions("system:level:add")
    @Log(title = "风险等级统计标", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ROrgRiskLevel rOrgRiskLevel)
    {
        return toAjax(rOrgRiskLevelService.insertROrgRiskLevel(rOrgRiskLevel));
    }

    /**
     * 修改风险等级统计标
     */
//    @RequiresPermissions("system:level:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ROrgRiskLevel rOrgRiskLevel = rOrgRiskLevelService.selectROrgRiskLevelById(id);
        mmap.put("rOrgRiskLevel", rOrgRiskLevel);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险等级统计标
     */
//    @RequiresPermissions("system:level:edit")
    @Log(title = "风险等级统计标", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ROrgRiskLevel rOrgRiskLevel)
    {
        return toAjax(rOrgRiskLevelService.updateROrgRiskLevel(rOrgRiskLevel));
    }

    /**
     * 删除风险等级统计标
     */
    @RequiresPermissions("system:level:remove")
    @Log(title = "风险等级统计标", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rOrgRiskLevelService.deleteROrgRiskLevelByIds(ids));
    }
}
